/* GUI CONVERTED from rspoamta.p (converter v1.75) Sat Aug 12 23:14:33 2000 */
/* rspoamta.p - Release Management Supplier Schedules                   */
/* Copyright 1986-2002 QAD Inc., Carpinteria, CA, USA.                  */
/* All rights reserved worldwide.  This is an unpublished work.         */
/*F0PN*/ /*V8:ConvertMode=Maintenance                                   */
/*K1Q4*/ /*V8:RunMode=Character,Windows                                 */
/* REVISION: 7.3    LAST MODIFIED: 10/12/92           BY: WUG *G462*    */
/* REVISION: 7.3    LAST MODIFIED: 07/19/93           BY: WUG *GD48*    */
/* REVISION: 7.3    LAST MODIFIED: 10/11/93           BY: WUG *GG24*    */
/* REVISION: 7.3    LAST MODIFIED: 10/19/94           BY: ljm *GN40*    */
/* REVISION: 7.3    LAST MODIFIED: 11/08/94           BY: ljm *GO33*    */
/* REVISION: 7.3    LAST MODIFIED: 04/09/95           BY: vrn *G0MD*    */
/* REVISION: 7.3    LAST MODIFIED: 07/17/95           BY: dzs *G0S8*    */
/* REVISION: 7.4    LAST MODIFIED: 10/24/96           BY: *H0NM* Aruna Patil */
/* REVISION: 7.4    LAST MODIFIED: 04/23/97           BY: *H0WH* Aruna Patil */

/* REVISION: 8.6E     LAST MODIFIED: 02/23/98   BY: *L007* A. Rahane */
/* REVISION: 8.6E     LAST MODIFIED: 05/20/98   BY: *K1Q4* Alfred Tan        */
/* REVISION: 8.6E     LAST MODIFIED: 10/04/98   BY: *J314* Alfred Tan        */
/* REVISION: 8.6E     LAST MODIFIED: 04/05/99   BY: *J3CB* Santosh Rao       */
/* REVISION: 9.1      LAST MODIFIED: 03/24/00 BY: *N08T* Annasaheb Rahane */
/* REVISION: 9.1      LAST MODIFIED: 08/12/00 BY: *N0KP* myb                 */
/* SCHEDULED PO EFFECTIVE ALLOCATION PERCENT MAINT */

{mfdeclre.i}
{gplabel.i} /* EXTERNAL LABEL INCLUDE */

/* ********** Begin Translatable Strings Definitions ********* */

&SCOPED-DEFINE rspoamta_p_1 "Purchase Order"
/* MaxLen: Comment: */

&SCOPED-DEFINE rspoamta_p_2 "Percent"
/* MaxLen: Comment: */

&SCOPED-DEFINE rspoamta_p_3 " Purchase Order Percents "
/* MaxLen: Comment: */

/* ********** End Translatable Strings Definitions ********* */

define input parameter part as character.
define input parameter site as character.
define input parameter effdate as date.

define variable i as integer.
define variable where_we_are as integer.
define variable del-yn like mfc_logical.
define variable qadwkfl_recid as recid.
define variable new_qad_wkfl like mfc_logical.
define variable total_percent as decimal.
define variable begstr as character.
/*H0NM*/ define variable is_first like mfc_logical.

begstr = string(site,"x(8)") + string(part,"x(18)")
+ string(year(effdate),"9999") + string(month(effdate),"99")
+ string(day(effdate),"99").

/*J3CB*/ /*V8:EditableDownFrame=det_frame */

FORM /*GUI*/ 
   space(5)
   qad_charfld[1]       label {&rspoamta_p_1}
   qad_decfld[1]        label {&rspoamta_p_2} format ">>9"
with frame det_frame 10 down centered
/*J3CB** /*GN40*/ /*V8-*/ scroll 1 /*V8+*/ attr-space width 80 */
/*J3CB*/ scroll 1 attr-space width 80
/*G0MD title "Purchase Order Percents". */
/*G0MD*/ title color normal (getFrameTitle("PURCHASE_ORDER_PERCENTS",33)) THREE-D /*GUI*/.


/* SET EXTERNAL LABELS */
setFrameLabels(frame det_frame:handle).

pause 0.

mainloop:
repeat transaction with frame det_frame:
/*GUI*/ if global-beam-me-up then undo, leave.

   clear frame det_frame all no-pause.
   view frame det_frame.

   find first qad_wkfl where qad_key1 = "poa_det"
   and qad_key2 begins begstr
   no-lock no-error.

   i = 0.
   do while i < frame-down and available qad_wkfl:
      display
      qad_charfld[1]
      qad_decfld[1].

      i = i + 1.
      if i < frame-down then down 1.

      find next qad_wkfl where qad_key1 = "poa_det"
      and qad_key2 begins begstr
      no-lock no-error.
   end.

   up frame-line - 1.

   find first qad_wkfl where qad_key1 = "poa_det"
   and qad_key2 begins begstr
   no-lock no-error.

   detail-loop:
   repeat with frame det_frame:
/*GUI*/ if global-beam-me-up then undo, leave.

      ststatus = stline[1].
      status input ststatus.

      prompt-for qad_charfld[1]
      go-on(F9 F10 CURSOR-UP CURSOR-DOWN).

      do while
      lastkey = keycode("F9")
      or lastkey = keycode("CURSOR-UP")
      or lastkey = keycode("F10")
      or lastkey = keycode("CURSOR-DOWN")
      on endkey undo, leave detail-loop:
     if available qad_wkfl then do:
        if lastkey = keycode("F9") or lastkey = keycode("CURSOR-UP")
        then do:
           display
           qad_charfld[1]
           qad_decfld[1].

           find prev qad_wkfl where qad_key1 = "poa_det"
           and qad_key2 begins begstr
           exclusive-lock no-error.

           if available qad_wkfl then do:
          up 1.
          display
          qad_charfld[1]
          qad_decfld[1].
           end.
           else do:
          find first qad_wkfl where qad_key1 = "poa_det"
          and qad_key2 begins begstr
          exclusive-lock no-error.
          bell.
           end.
        end.

        else
        if lastkey = keycode("F10") or lastkey = keycode("CURSOR-DOWN")
        then do:
           display
           qad_charfld[1]
           qad_decfld[1].

           find next qad_wkfl where qad_key1 = "poa_det"
           and qad_key2 begins begstr
           exclusive-lock no-error.
           if available qad_wkfl then do:
          down 1.
          display
          qad_charfld[1]
          qad_decfld[1].
           end.
           else do:
/*H0NM*/      /* FIND LAST STATEMENTS WITH BEGINS RETURNS NO VALUES IN ORACLE
*/

              find last qad_wkfl where qad_key1 = "poa_det"
/*H0NM**         and qad_key2 begins begstr */
/*H0NM*/         and qad_key2 >= begstr and qad_key2 <= begstr + fill(hi_char,8)
              exclusive-lock no-error.
              bell.
           end.
        end.
     end. /* if available qad_wkfl */

     ststatus = stline[1].
     status input ststatus.

     prompt-for qad_charfld[1]
     go-on(F9 F10 CURSOR-UP CURSOR-DOWN).
      end. /* do while lookup */

      find qad_wkfl where qad_key1 = "poa_det"
/*H0WH** and qad_key2 = begstr + string(input qad_charfld[1],"x(30)") */
/*H0WH*/ and qad_key2 = begstr + input qad_charfld[1]
      exclusive-lock no-error.

      find po_mstr where po_nbr = input qad_charfld[1]
      no-lock no-error.
      if not available po_mstr then do:
     {mfmsg.i 343 3}
     undo, retry.
      end.

      if not po_sched then do:
     {mfmsg.i 8178 3}
     bell.
     undo, retry.
      end.

      /*GG24 ADDED FOLLOWING SECTION*/
      find first pod_det
      where pod_part = part
      and pod_nbr = po_nbr
      no-lock no-error.

      if not available pod_det then do:
     {mfmsg.i 8203 3}
     undo, retry.
      end.

      find first pod_det
      where pod_part = part
      and pod_nbr = po_nbr
      and pod_site = site
      no-lock no-error.

      if not available pod_det then do:
     {mfmsg.i 8170 3}
     undo, retry.
      end.
      /*GG24 END SECTION*/

      if not available qad_wkfl then do:
     new_qad_wkfl = yes.

     {mfmsg.i 1 1}
     create qad_wkfl.
     assign
     qad_key1 = "poa_det"
/*H0WH** qad_key2 = begstr + string(input qad_charfld[1],"x(30)") */
/*H0WH*/ qad_key2 = begstr + input qad_charfld[1]
     qad_key3 = "poa_det"
     qad_key4 =
     string(input qad_charfld[1],"x(30)")
     + string(part,"x(18)")
     + string(site,"x(8)")
     + string(year(effdate),"9999") + string(month(effdate),"99")
     + string(day(effdate),"99")
     qad_charfld[1]  /* PO */
     qad_charfld[2] = part
     qad_charfld[3] = site
     qad_datefld[1] = effdate
     qad_decfld[1].
      end.
      else new_qad_wkfl = no.

      qadwkfl_recid = recid(qad_wkfl).

/*H0NM*/ /* POSITION CURSOR ON NEW RECORD */
/*H0NM*/ if new_qad_wkfl and dbtype("qaddb") = "ORACLE" then do:
/*H0NM*/    find qad_wkfl where recid(qad_wkfl) = qadwkfl_recid
/*H0NM*/    exclusive-lock no-error.
/*H0NM*/ end.

      where_we_are = frame-line.

/*H0NM*/ is_first = false.

      do i = 1 to where_we_are while available qad_wkfl:
     find prev qad_wkfl where qad_key1 = "poa_det"
     and qad_key2 begins begstr no-lock no-error.

/*H0NM*/  /* IF NOT AVAIL THEN WE'VE HIT THE FIRST RECORD */
/*H0NM*/  if not available qad_wkfl then is_first = true.
      end.

/*H0NM*/ /* FORCE CURSOR POSITIONING TO ENSURE THE NEXT REC IS THE FIRST ONE */
/*H0NM*/ if is_first and dbtype("qaddb") = "ORACLE" then do:

/*J3CB*/ /* WHEN THE FIND PREV LOOP ABOVE FAILS IN ORACLE - THE CURSOR       */
/*J3CB*/ /* REMAINS ON THE FIRST RECORD. THE FIND NEXT STATEMENT BELOW       */
/*J3CB*/ /* PLACES THE CURSOR ON THE SECOND RECORD. THUS THE FOLLOWING CODE  */
/*J3CB*/ /* IS COMMENTED                                                     */

/*J3CB** BEGIN DELETE **
 * /*H0NM*/   is_first = false.
 *
 * /*H0NM*/ /* MOVE CURSOR TO NEXT RECORD (IF EXISTS). THE CURSOR POSITIONING */
 * /*H0NM*/ /* FROM THE SECOND RECORD WILL POINT TO BEFORE THE FIRST RECORD   */
 * /*H0NM*/ /* WHEN THE FIND PREV LOOP BELOW FAILS - THE CURSOR STARTING FROM */
 * /*H0NM*/ /* THE FIRST RECORD WILL REMAIN POINTING TO THE FIRST RECORD WHEN */
 * /*H0NM*/ /* THE FIND PREV LOOP FAILS.                                      */
 * /*H0NM*/   find next qad_wkfl where qad_key1 = "poa_det"
 * /*H0NM*/   and qad_key2 begins begstr no-lock no-error.
 *
 * /*H0NM*/   /* IF THERE IS NOT ANOTHER RECORD WE WANT TO DO A FIND FIRST */
 * /*H0NM*/   /* RATHER THAN A FIND NEXT - WITH ONE RECORD IN THE SET, THE */
 * /*H0NM*/   /* FIND NEXT RETURNS NO RECORDS BECUASE THE CURSOR IS STUCK  */
 * /*H0NM*/   /* ALREADY POINTING TO THE FIRST RECORD - THERE ISN'T A NEXT */
 * /*H0NM*/   if not available qad_wkfl then is_first = true.
 *J3CB** END DELETE **/

/*H0NM*/   do i = 1 to where_we_are + 1  while available qad_wkfl:
/*H0NM*/      find prev qad_wkfl where qad_key1 = "poa_det"
/*H0NM*/      and qad_key2 begins begstr no-lock no-error.
/*H0NM*/   end.
/*H0NM*/ end.

      up where_we_are - 1.

      do i = 1 to frame-down:

/*H0NM*/  /* IF THIS IS THE ONE AND ONLY RECORD IN THE SET, */
/*H0NM*/  /* DO A FIND FIRST                                */
/*H0NM*/  if i = 1 and is_first and dbtype("qaddb") = "ORACLE" then do:
/*H0NM*/     find first qad_wkfl where qad_key1 = "poa_det"
/*H0NM*/     and qad_key2 begins begstr no-lock no-error.

/*H0NM*/     display
/*H0NM*/     qad_charfld[1]
/*H0NM*/     qad_decfld[1].

/*H0NM*/     if recid(qad_wkfl) = qadwkfl_recid then do:
/*H0NM*/        where_we_are = frame-line.
/*H0NM*/     end.
/*H0NM*/     is_first = false.
/*H0NM*/  end.
/*H0NM*/  else do:
        find next qad_wkfl where qad_key1 = "poa_det"
        and qad_key2 begins begstr no-lock no-error.

        if available qad_wkfl then do:
           display
           qad_charfld[1]
           qad_decfld[1].

           if recid(qad_wkfl) = qadwkfl_recid then do:
              where_we_are = frame-line.
           end.
        end.
        else do:
           display
           "" @ qad_charfld[1]
           "" @ qad_decfld[1].
        end.
/*H0NM*/  end.
     if i < frame-down then down 1.
      end.

      up frame-down - where_we_are.

      find qad_wkfl where recid(qad_wkfl) = qadwkfl_recid exclusive-lock.
      qadwkfl_recid = recid(qad_wkfl).

      ststatus = stline[2].
      status input ststatus.

      pause before-hide.                                                /*GD48*/
      prompt-for qad_decfld[1]
/*GO33*/ /*V8+*/      
      go-on(ESC F5 CTRL-D F9 F10 CURSOR-UP CURSOR-DOWN).   
      pause 0.                                                         /*GD48*/

      datafield-update:
      do while
      lastkey = keycode("F9")
      or lastkey = keycode("CURSOR-UP")
      or lastkey = keycode("F10")
      or lastkey = keycode("CURSOR-DOWN"):
     new_qad_wkfl = no.

     if lastkey = keycode("F9") or lastkey = keycode("CURSOR-UP")
     then do:
        assign
        qad_decfld[1].

        find prev qad_wkfl where qad_key1 = "poa_det"
        and qad_key2 begins begstr exclusive-lock no-error.

        if available qad_wkfl then do:
           up 1.
           display
           qad_charfld[1]
           qad_decfld[1].
        end.
        else do:
           find first qad_wkfl where qad_key1 = "poa_det"
           and qad_key2 begins begstr exclusive-lock no-error.
           bell.
        end.
     end.

     else
     if lastkey = keycode("F10") or lastkey = keycode("CURSOR-DOWN")
     then do:
        assign
        qad_decfld[1].

        find next qad_wkfl where qad_key1 = "poa_det"
        and qad_key2 begins begstr exclusive-lock no-error.
        if available qad_wkfl then do:
           down 1.
           display
           qad_decfld[1].
        end.
        else do:
/*H0NM*/        /* FIND LAST WITH BEGINS RETURNS NO VALUES IN ORACLE */

           find last qad_wkfl where qad_key1 = "poa_det"
/*H0NM**      and qad_key2 begins begstr exclusive-lock no-error.*/
/*H0NM*/      and qad_key2 >= begstr and qad_key2 <= begstr + fill(hi_char,8)
/*H0NM*/   exclusive-lock no-error.
           bell.
        end.
     end.

     ststatus = stline[2].
     status input ststatus.

     pause before-hide.                                             /*GD48*/
     prompt-for qad_decfld[1]
     go-on(PF4 F4 F5 CTRL-D CTRL-E F9 F10 CURSOR-UP CURSOR-DOWN).
     pause 0.                                                       /*GD48*/
      end. /* datafield-update */

      if lastkey = keycode("F5") or lastkey = keycode("CTRL-D") then do:
     del-yn = yes.
     {mfmsg01.i 11 1 del-yn}
     if del-yn = no then do:
        display
        qad_charfld[1]
        qad_decfld[1].
        next detail-loop.
     end.

     find qad_wkfl where qad_key1 = "poa_det"
/*H0WH** and qad_key2 = begstr + string(input qad_charfld[1],"x(30)") */
/*H0WH*/ and qad_key2 = begstr + input qad_charfld[1]
     exclusive-lock no-error.

     delete qad_wkfl.

     where_we_are = frame-line.

     find next qad_wkfl where qad_key1 = "poa_det"
     and qad_key2 begins begstr no-lock no-error.

     if available qad_wkfl then do:
        qadwkfl_recid = recid(qad_wkfl).

        display
        qad_charfld[1]
        qad_decfld[1].

        do i = where_we_are to frame-down - 1:
           down 1.
           find next qad_wkfl where qad_key1 = "poa_det"
           and qad_key2 begins begstr no-lock no-error.

           if available qad_wkfl then do:
          display
          qad_charfld[1]
          qad_decfld[1].
           end.
           else do:
          display
          "" @ qad_charfld[1]
          "" @ qad_decfld[1].
           end.
        end.

        up frame-down - where_we_are.
        find qad_wkfl where recid(qad_wkfl) = qadwkfl_recid exclusive-lock.
     end.
     else do:
        display
        "" @ qad_charfld[1]
        "" @ qad_decfld[1].

        find prev qad_wkfl where qad_key1 = "poa_det"
        and qad_key2 begins begstr exclusive-lock no-error.

        if available qad_wkfl then do:
           up 1.
           display
           qad_charfld[1]
           qad_decfld[1].
        end.
     end.
      end. /* if lastkey = F5 */

      else
      if lastkey = keycode("CTRL-E")
      or lastkey = keycode("F4")
      or lastkey = keycode("PF4")
      then do:
     display
     qad_decfld[1].
      end.

      else do:
     assign
     qad_decfld[1].

     if new_qad_wkfl and frame-line <> frame-down then do:
        qadwkfl_recid = recid(qad_wkfl).

        where_we_are = frame-line.

/*H0NM*/     /* FOR SOME REASON, THE CURSOR POSITIONING IS WORKING */
/*H0NM*/     /* OK HERE IN ORACLE                                  */
        do i = 1 to where_we_are + 1 while available qad_wkfl:
           find prev qad_wkfl where qad_key1 = "poa_det"
           and qad_key2 begins begstr no-lock no-error.
            end.

        up where_we_are - 1.

        do i = 1 to frame-down:
           find next qad_wkfl where qad_key1 = "poa_det"
           and qad_key2 begins begstr no-lock no-error.

           if available qad_wkfl then do:
          display
          qad_charfld[1]
          qad_decfld[1].

          if recid(qad_wkfl) = qadwkfl_recid then do:
             where_we_are = frame-line.
          end.
           end.
           else do:
          display
          "" @ qad_charfld[1]
          "" @ qad_decfld[1].
           end.

           if i < frame-down then down 1.
        end.

        up frame-down - where_we_are.
        find qad_wkfl where recid(qad_wkfl) = qadwkfl_recid exclusive-lock.
        qadwkfl_recid = recid(qad_wkfl).
     end.
/*F312 END SECTION*/

      end.
   end.
/*GUI*/ if global-beam-me-up then undo, leave.
  /* detail-loop */

   total_percent = 0.
   for each qad_wkfl exclusive-lock
   where qad_key1 = "poa_det" and qad_key2 begins begstr:
      total_percent = total_percent + qad_decfld[1].
   end.

/*G0S8*/ /* IGNORE CHECKING OF TOTAL PERCENTAGE = 100  FOR SUBCONTRACT ORDERS */
/*G0S8*/ find first pod_det where pod_part = part
/*G0S8*/ and pod_nbr = input qad_charfld[1]
/*G0S8*/ and pod_site = site no-lock no-error.

/*G0S8   if not (total_percent = 100 or total_percent = 0) then do: */
/*G0S8*/ if not (total_percent = 100 or total_percent = 0)
/*G0S8*/ and pod_type <> "S" then do:
         {mfmsg.i 8180 3}
         bell.
     end.
     else do:
          leave.
     end.
end.
/*GUI*/ if global-beam-me-up then undo, leave.


ststatus = stline[2].
status input ststatus.
hide frame det_frame no-pause.
pause before-hide.
